from tortoise import fields
from tortoise.models import Model

# class User(Model):
#     id = fields.IntField(pk=True)  # 主键，自增
#     username = fields.CharField(max_length=50, unique=True)  # 用户名，唯一
#     email = fields.CharField(max_length=100, unique=True)  # 邮箱，唯一
#     is_active = fields.BooleanField(default=True)  # 是否激活
#     created_at = fields.DatetimeField(auto_now_add=True)  # 创建时间
#     updated_at = fields.DatetimeField(auto_now=True)  # 更新时间


class BaseModel(Model):
    """
    基础模型
    """
    created_time = fields.DatetimeField(auto_now_add=True)
    update_time = fields.DatetimeField(auto_now=True)

    class Meta:
        abstract = True


class Conversation(BaseModel):
    """
    对话模型
    """
    conversation_id = fields.CharField(max_length=255, primary_key=True)
    title = fields.CharField(max_length=255, default='新对话')

class Message(BaseModel):
    """
    消息模型
    """
    message_id = fields.CharField(max_length=32, primary_key=True)
    content = fields.TextField()
    conversation_id = fields.CharField(max_length=32)
    message_source = fields.IntField()

    class Meta:
        unique_together = ('conversation_id', 'message_id')


class FileRecord(BaseModel):
    """
    附件模型
    """
    file_id = fields.CharField(max_length=32, primary_key=True)
    file_name = fields.CharField(max_length=255)
    file_size = fields.DecimalField(max_digits=24, decimal_places=6)
    file_type = fields.IntField(null=True)
    message_id = fields.CharField(max_length=32)
    url = fields.CharField(max_length=255)
    oss_key = fields.CharField(max_length=255, null=True)
    oss_bucket = fields.CharField(max_length=255, null=True)



class TestSuite(BaseModel):
    """
    测试集模型
    """
    suite_id = fields.CharField(max_length=32, primary_key=True)
    conversation_id = fields.CharField(max_length=255)
    message_id = fields.CharField(max_length=255, null=True)

    class Meta:
        unique_together = ('conversation_id', 'suite_id')

class TestCase(BaseModel):
    """
    测试用例模型
    """
    case_id = fields.CharField(max_length=32, primary_key=True)
    case_num = fields.CharField(max_length=255)
    expected = fields.TextField()
    feature = fields.CharField(max_length=255)
    preconditions = fields.TextField(null=True,default="")
    step = fields.TextField()
    suite_id = fields.CharField(max_length=32)
    test_scene = fields.CharField(max_length=255)



